package org.pc2r.game;

import java.io.Closeable;
import java.io.IOException;
import java.net.Socket;
import java.util.UUID;

import org.pc2r.protocole.message.Message;

public class Client implements Closeable {

	static final private int port = 2012;
	
	private String name = UUID.randomUUID().toString();
	private Game game = new Game();

	public Client() throws IOException {
	  this(port);
	}
	
	public Client(int port) throws IOException {
	  this("127.0.0.1", port);
	}
	
	public Client(String host, int port) throws IOException {
	  Socket socket = new Socket(host, port);
    game.addPlayer(name, socket);
	}
	
	public String getName() {
	  return name;
	}
	
	public void send(Message message) throws IOException {	
		game.send(name, message);
	}

	public String read() throws IOException {
    return game.read(name);
	}

  @Override
  public void close() {
    game.close();
  }
}
